//载入那些函数库
let includes = ([
    "include/common.js",
]);

let inherits = ([
    "inherit/data.js",
]);

function create() {
    return thisObject;
}


function main(me, arg) {

    // os.debug(arg,"传进来的参数");

    let args = arg.split(" ");

    // os.debug(JSON.stringify(args), "参数结构");

    os.debug(me,"debuger");


    //根据文件名查找哪些类模板继承了自己...
    if (args[0] == "ls" && args[1] != "" && args[2] == "sub") {
        let gt = os.getGlobalThis();
        // gt.metaClassSource.push({file: file, cmpl: cmpl, src: ""});
        //__subsFile__
        let result = subList(args[1]);
        //注意，返回的是一个function....
        if (!arrayp(result)) {
            tellObject(me, "系统中不存在该模板").to();
            return;
        }

        let str = "";
        result.forEach(e => {
            str += e + "\n";
        });
        str = `共${result.length}个类模板继承该类模板\n` + str + "\n";
        tellObject(me, str).to();
        return;
    }


    //检查对象是否继承了指定的模板，注意是对象
    if (args[0] == "ls" && args[1] != "" && args[2] == "chkins") {

        if (verifyInherits(baseFileName(me), args[1])) {
            tellObject(me,fileNameSid(me)+" 继承了 "+ "  " +args[1]).to();
        }else{
            tellObject(me,fileNameSid(me)+" 没有继承 "+ "  " +args[1]).to();
        }
        return;
    }


    // obs ls id inh
    // 查看对象继承了谁

    if (args[0] == "ls" && args[1] != "" && args[2] == "inh") {

        //对象支持 id和filesid查找
        let fileSid, findOb;
        if (args[1].indexOf("#") > -1) {//fileSid查找

        } else {
            findOb = present(args[1]);
        }


        if (!objectp(findOb)) {
            tellObject(me, "系统中不存在该对象").to();
            return;
        }

        //打印对象的继承....
        //os.debug( JSON.stringify(findOb.data),"查到的对象" );
        os.debug(JSON.stringify(findOb.__parents__meta__file__), "对象的继承列表");
        tellObject(me, "查看指定对象 继承了哪些模板。。。").to();
        return;
    }



        if (args[0] == "ls") {
        let obs = getObjects();
        let name, str = "对象有\n";
        for (let e in obs) {
            if (undefinedp(obs[e].get)) {
                name = "<>";
            } else {
                name = obs[e].get("name");
            }
            str += `${name} -> ${fileNameSid(obs[e])}\n`;
        }
        str += "\n\n模板有:\n";
        let gt = os.getGlobalThis();
        let type ;
        gt.metaClassSource.forEach(e => {
            type = e.cmpl.__metaType__ == "isClass" ? "类模板实例":"类模板对象";
            str += `${e.file}:${type}\n`;
        });

        os.debug(str);
        tellObject(me, str).to();
    }
}